﻿<div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto" style="padding-top:0px;padding-bottom:0px;">
		<div class="layui-form-item">
			<div class="layui-inline" style="margin-right: 0;">
				<label class="layui-form-label" style="padding:0px;padding-right: 5px;width:100px;">
					<select id="dropSearchName">
						<option value="Province">省份名称</option>
						<option value="City">城市名称</option>
						<option value="Area">区域名称</option>
						<option value="PostCode">邮政编码</option>
						<option value="AreaCode">区号</option>
					</select>
				</label>
				<div class="layui-input-inline" style="margin: 0px;">
					<input type="text" class="layui-input" id="txtSearchKeyword" name="txtSearchKeyword" placeholder="请输入搜索关键字" autocomplete="off" onkeypress="javascript:return DefaultButton(event, 'btnSearch')">
				</div>
			</div>
			<div class="layui-inline">
				<button id="btnSearch" type="button" class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="btnSearch">
					<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
				</button>
			</div>
		</div>
	</div>
	<div class="layui-card-body">
		<table id="tblList" lay-filter="tblList"></table>
		<script type="text/html" id="toolbarHead">
			<div class="layui-form-item" style="margin: auto;">
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="btnDeleteMulti">批量删除</button>
					<button class="layui-btn layuiadmin-btn-list" onclick="layer_show('添加','/Admin/Plus/RegionEdit')">添加</button>
				</div>
			</div>
		</script>
		<script type="text/html" id="tblBarCol">
			<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-search"></i>查看</a>
			<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
			<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
		</script>
	</div>
</div>
@Html.AntiForgeryToken()
@section scripts {
	<script type="text/javascript">
		layui.use(['form', 'table', 'element'], function () {
			var table = layui.table;
			var form = layui.form;
			var element = layui.element;

			//加载表格
			table.render({
				elem: '#tblList'
				, url: '/Admin/Plus/GetRegionList'
				, toolbar: '#toolbarHead'
				, where: GetSearchParam()
				, request: {
					pageName: 'PageNum' //页码的参数名称，默认：page
					, limitName: 'PageSize' //每页数据量的参数名，默认：limit
				}
				, cols: [[
					{ type: "checkbox", width: 30, fixed: "left", align: 'center' },
					{ field: 'Country', minWidth: 200, title: '国家', align: 'center' },
					{ field: 'Province', minWidth: 200, title: '省份', align: 'center'},
					{ field: 'City', minWidth: 200, title: '城市', align: 'center'},
					{ field: 'Area', minWidth: 200, title: '区域', align: 'center'},
					{ field: 'PostCode', minWidth: 200, title: '邮政编码', align: 'center' },
					{ field: 'AreaCode', minWidth: 200, title: '区号', align: 'center'},
					{ field: 'RegionID', width: 230, title: '操作', fixed: "right", align: "center", templet: '#tblBarCol' }
				]]
				, parseData: function (res) { //res 即为原始返回的数据
					return {
						"code": 0, //解析接口状态
						"msg": "", //解析提示文本
						"count": res.RecordTotal, //解析数据长度
						"data": res.RowList //解析数据列表
					};
				}
				, limits: [10, 15, 20, 25, 50, 100]
				, limit: 15
				, page: true
			});
			//监听表格操作列
			table.on('tool(tblList)', function (obj) {
				if (obj.event === 'view') {
					layer_show('查看', '/Admin/Plus/RegionView?id=' + obj.data.RegionID);
					return false;
				} else if (obj.event === 'edit') {
					layer_show('编辑', '/Admin/Plus/RegionEdit?id=' + obj.data.RegionID);
					return false;
				} else if (obj.event === 'del') {
					DeleteSingle(obj.data.RegionID,"/Admin/Plus/DelRegion");
					return false;
				}
			});
			//监听搜索操作
			form.on('submit(btnSearch)', function (data) {
				reloadTable();
				return false;
			});
			//监听批量删除
			form.on('submit(btnDeleteMulti)', function (data) {
				var checkStatus = table.checkStatus('tblList');
				var data = checkStatus.data;
				var ids = "";
				for (j = 0, len = data.length; j < len; j++) {
					if (j < len - 1) {
						ids += data[j].RegionID + ',';
					} else {
						ids += data[j].RegionID;
					}
				}
				DeleteMulti(ids, '/Admin/Plus/DelRegionMulti');
				return false;
			});

			//表格重载
			function reloadTable(tableID = 'tblList') {
				table.reload(tableID, {
					page: {
						curr: 1
					}
					, where: GetSearchParam()
				}, 'data');
			};
			function GetSearchParam() {
				var SearchName = $("#dropSearchName").val();
				var SearchKeyword = $("#txtSearchKeyword").val();
				var objParam = { "SearchName": SearchName, "SearchKeyword": SearchKeyword };
				return objParam;
			};
		});
	</script>
}



